import React from "react";
import {
  UserOutlined,
  CarOutlined,
  UserSwitchOutlined,
  UsergroupAddOutlined,
  AccountBookOutlined,
  BarChartOutlined,
} from "@ant-design/icons";

const siderData = [
  { key: "/main/home", label: "首页" },
  {
    subMenuKey: "sub1",
    icon: <UserOutlined />,
    title: "管理员管理",
    children: [
      { key: "/main/adminsList", label: "查看管理列表" },
      { key: "/main/addAdmin", label: "新增管理员", roles: ["超级管理员"] },
    ],
  },
  {
    subMenuKey: "sub2",
    icon: <CarOutlined />,
    title: "车辆管理",
    children: [{ key: "/main/carsList", label: "车辆列表" }],
  },
  {
    subMenuKey: "sub3",
    icon: <UserSwitchOutlined />,
    title: "用户管理",
    children: [{ key: "/main/usersList", label: "查看用户列表" }],
  },
  {
    subMenuKey: "sub4",
    icon: <UserSwitchOutlined />,
    title: "车主管理",
    children: [
      { key: "/main/ownersList", label: "查看车主列表" },
      { key: "/main/checkOwner", label: "车主审核" },
      { key: "/main/addOwner", label: "车主申请" },
    ],
  },
  {
    subMenuKey: "sub5",
    icon: <AccountBookOutlined />,
    title: "订单管理",
    children: [{ key: "/main/ordersList", label: "查看订单列表" }],
  },
  {
    subMenuKey: "sub6",
    icon: <BarChartOutlined />,
    title: "评价管理",
    children: [
      { key: "/main/remarkList", label: "评价列表" },
      { key: "/main/remarkChart", label: "评价图表" },
    ],
  },
];

export default siderData;

export function filterSider(data) {
  const userInfo = JSON.parse(localStorage.getItem("userInfo"));
  const role = (userInfo || {}).role;

  return data.filter((item, index) => {
    return !item.roles || item.roles.includes(role);
  });
}
